﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SmartRfMng.appcode;

namespace SmartRfMng
{
    public partial class frmSet : Form
    {
        private string Host = string.Empty;
        private string WebSvr = string.Empty;
        private bool IsSnyTime = false;
        private string OrgCode = string.Empty;
        private string TimeOut = string.Empty;
        private string PrnName = string.Empty;

        public frmSet()
        {
            InitializeComponent();
        }

        private void btncancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmSet_Load(object sender, EventArgs e)
        {
            WebSvr = ZT_INI.GetINI("system", "WebSvr", "FcWlsRf");
            Host = ZT_INI.GetINI("system", "Host", "");
            IsSnyTime = ZT_INI.GetINI("system", "SnyTime", "0") == "1";
            OrgCode = ZT_INI.GetINI("system", "OrgCode", "00");
            TimeOut = ZT_INI.GetINI("system", "TimeOut", "30");
            PrnName = ZT_INI.GetINI("system", "PrnName", "SP200");

            txtServerIp.Text = Host;
            txtServiceName.Text = WebSvr;
            txtOrgCode.Text = OrgCode;
            cbChkSny.Checked = IsSnyTime;
            txtTimeOut.Text = TimeOut;
            txtPrnName.Text = PrnName;
        }

        private void btnok_Click(object sender, EventArgs e)
        {
            if (txtServerIp.Text.Trim() == "")
            {
                MessageBox.Show("服务器IP地址不允许为空！", "客户分销");
                return;
            }

            if (txtServiceName.Text.Trim() == "")
            {
                MessageBox.Show("服务名不允许为空！", "客户分销");
                return;
            }

            //if (txtOrgCode.Text.Trim() == "")
            //{
            //    MessageBox.Show("门店不允许为空！", "客户分销");
            //    return;
            //}

            if (txtPrnName.Text.Trim() == "")
            {
                MessageBox.Show("打印机名称不允许为空！", "客户分销");
                return;
            }

            if (txtTimeOut.Text.Trim() == "")
            {
                MessageBox.Show("超时时间不允许为空！", "客户分销");
                return;
            }

            Host = txtServerIp.Text.Trim();
            WebSvr = txtServiceName.Text.Trim();
            IsSnyTime = cbChkSny.Checked;
            OrgCode = txtOrgCode.Text;
            TimeOut = txtTimeOut.Text.Trim();
            PrnName = txtPrnName.Text.Trim();

            string sSnyTime = string.Empty;
            if (IsSnyTime)
            {
                sSnyTime = "1";
            }
            else
            {
                sSnyTime = "0";
            }

            ZT_INI.PutINI("system", "WebSvr", WebSvr);
            ZT_INI.PutINI("system", "Host", Host);
            ZT_INI.PutINI("system", "SnyTime", sSnyTime);
            ZT_INI.PutINI("system", "OrgCode", OrgCode);
            ZT_INI.PutINI("system", "TimeOut", TimeOut);
            ZT_INI.PutINI("system", "PrnName", PrnName);
            this.Close();
        }

        private void txtTimeOut_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8 && e.KeyChar != (char)13)
            {
                e.Handled = true;
            }
        }


    }
}